const http = require("http");
const fs = require("fs");
const url = require("url");
const querystring = require("querystring");

http.createServer((req,res)=>{
  let {pathname,query} = url.parse(req.url,true);
 /* let  rs = fs.createReadStream(`${pathname}`);
  rs.pipe(req)*/
  if(req.headers['origin']=='null' || req.headers['origin'].startsWith('http://localhost')){
    res.setHeader('Access-Control-Allow-Origin', '*');
  }
  let arr = [];
  req.on('data',data=>{
    arr.push(data);
  })
  req.on("end",()=>{
    let post=querystring.parse(Buffer.concat(arr).toString());
    console.log(post)
    res.write("123");
    res.end();
  })
  
}).listen(8080);
